<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php /** @var $block \Magento\Bundle\Block\Adminhtml\Sales\Order\Items\Renderer */ ?>

<?php $_item = $block->getItem() ?>
<?php $items = array_merge([$_item->getOrderItem()], $_item->getOrderItem()->getChildrenItems()) ?>
<?php $shipItems = $block->getChildren($_item) ?>
<?php $_count = count($items) ?>
<?php $_index = 0 ?>

<?php $_prevOptionId = '' ?>

<?php if ($block->getOrderOptions() || $_item->getDescription()): ?>
    <?php $_showlastRow = true ?>
<?php else: ?>
    <?php $_showlastRow = false ?>
<?php endif; ?>

<?php foreach ($items as $_item): ?>
    <?php $block->setPriceDataObject($_item) ?>
    <?php if ($_item->getParentItem()): ?>
        <?php $attributes = $block->getSelectionAttributes($_item) ?>
        <?php if ($_prevOptionId != $attributes['option_id']): ?>
        <tr>
            <td class="col-product"><div class="option-label"><?php /* @escapeNotVerified */ echo $attributes['option_label'] ?></div></td>
            <td class="col-qty last">&nbsp;</td>
        </tr>
        <?php $_prevOptionId = $attributes['option_id'] ?>
        <?php endif; ?>
    <?php endif; ?>
    <tr<?php echo(++$_index == $_count && !$_showlastRow) ? ' class="border"' : '' ?>>
        <?php if (!$_item->getParentItem()): ?>
        <td class="col-product">
            <div class="product-title"><?php echo $block->escapeHtml($_item->getName()) ?></div>
            <div class="product-sku-block">
                <span><?php /* @escapeNotVerified */ echo __('SKU') ?>:</span>
                <?php echo implode('<br />', $this->helper('Magento\Catalog\Helper\Data')->splitSku($block->escapeHtml($_item->getSku()))); ?>
            </div>
        </td>
        <?php else: ?>
        <td class="col-product"><div class="option-value"><?php echo $block->getValueHtml($_item)?></div></td>
        <?php endif; ?>
        <td class="col-qty last">
            <?php if (($block->isShipmentSeparately() && $_item->getParentItem()) || (!$block->isShipmentSeparately() && !$_item->getParentItem())): ?>
                <?php if (isset($shipItems[$_item->getId()])): ?>
                    <?php /* @escapeNotVerified */ echo $shipItems[$_item->getId()]->getQty()*1 ?>
                <?php elseif ($_item->getIsVirtual()): ?>
                    <?php /* @escapeNotVerified */ echo __('N/A') ?>
                <?php else: ?>
                    0
                <?php endif; ?>
            <?php else: ?>
                &nbsp;
            <?php endif; ?>
        </td>
    </tr>
<?php endforeach; ?>
<?php if ($_showlastRow): ?>
    <tr class="border">
        <td class="col-product">
            <?php if ($block->getOrderOptions($_item->getOrderItem())): ?>
                <dl class="item-options">
                <?php foreach ($block->getOrderOptions($_item->getOrderItem()) as $option): ?>
                    <dt><?php /* @escapeNotVerified */ echo $option['label'] ?></dt>
                    <dd>
                    <?php if (isset($option['custom_view']) && $option['custom_view']): ?>
                        <?php /* @escapeNotVerified */ echo $option['value'];?>
                    <?php else: ?>
                        <?php echo $block->truncateString($option['value'], 55, '', $_remainder);?>
                        <?php if ($_remainder):?>
                            ... <span id="<?php /* @escapeNotVerified */ echo $_id = 'id' . uniqid()?>"><?php /* @escapeNotVerified */ echo $_remainder ?></span>
                            <script>
require(['prototype'], function(){

                            $('<?php /* @escapeNotVerified */ echo $_id ?>').hide();
                            $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseover', function(){$('<?php /* @escapeNotVerified */ echo $_id ?>').show();});
                            $('<?php /* @escapeNotVerified */ echo $_id ?>').up().observe('mouseout',  function(){$('<?php /* @escapeNotVerified */ echo $_id ?>').hide();});

});
</script>
                        <?php endif;?>
                    <?php endif;?>
                    </dd>
                <?php endforeach; ?>
                </dl>
            <?php endif; ?>
            <?php echo $block->escapeHtml($_item->getDescription()) ?>
        </td>
        <td class="last">&nbsp;</td>
    </tr>
<?php endif; ?>
